/** BrownianApplet.java
 *
 *	Lil Applet for visualizing geometric series.
 *	Author: Ralph Gootee (c) 2007
 *	GPL License 
 **/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;


public class BrownianApplet extends JApplet 
	implements ChangeListener,ActionListener
{
	private int defaultN = 15000;

	private BrownianPanel bPanel;
	private JSlider timeSlider;
	private JButton reconstructButton;
	
	//--------------------------------------------------------------------------
	public void init() {

		Container cp = getContentPane();	
		cp.setLayout(new BorderLayout());

		bPanel = new BrownianPanel(defaultN);
		cp.add(bPanel);
	
		JPanel bottomPanel = new JPanel();
		bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); 
		cp.add(bottomPanel,BorderLayout.SOUTH);
		
		timeSlider = new JSlider();
		timeSlider.addChangeListener(this);
		timeSlider.setMinimum(0);
		timeSlider.setMaximum(defaultN);
		timeSlider.setValue(defaultN);
		bottomPanel.add(timeSlider);
		
		reconstructButton = new JButton("Reconstruct");
		reconstructButton.addActionListener(this);
		bottomPanel.add(reconstructButton);
	}
	
	//------------------------------------------------------------------------------
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == reconstructButton){
			bPanel.reconstruct();
		}
	}
	
	//------------------------------------------------------------------------------
	public void stateChanged(ChangeEvent e) {
    	JSlider source = (JSlider)e.getSource();
    	
		if (!source.getValueIsAdjusting()){
			if(source == timeSlider){
				bPanel.setT(timeSlider.getValue());
			}
		}
	}
	
}